package edu.ncsu.csc326.coffeemaker;

import edu.ncsu.csc326.coffeemaker.exceptions.InventoryException;
import edu.ncsu.csc326.coffeemaker.exceptions.RecipeException;
import junit.framework.TestCase;

/*
 * Errors found:
 * 	wrong condition for addSugar()
 */

/**
 * 
 * @author Filipe Betzel
 *
 * Unit tests for Inventory class.
 */
public class InventoryTest extends TestCase {
	
	private CoffeeMaker cm;
	private Recipe r1;
	private Recipe r2;
	private Recipe r3;
	private Recipe r4;
	private Inventory I;

	protected void setUp() throws Exception {
		cm = new CoffeeMaker();
		
		I = new Inventory();
		
		//Set up for r1
		r1 = new Recipe();
		r1.setName("Coffee");
		r1.setAmtChocolate("0");
		r1.setAmtCoffee("3");
		r1.setAmtMilk("1");
		r1.setAmtSugar("1");
		r1.setPrice("50");
		
		//Set up for r2
		r2 = new Recipe();
		r2.setName("Mocha");
		r2.setAmtChocolate("20");
		r2.setAmtCoffee("3");
		r2.setAmtMilk("1");
		r2.setAmtSugar("1");
		r2.setPrice("75");
		
		//Set up for r3
		r3 = new Recipe();
		r3.setName("Latte");
		r3.setAmtChocolate("0");
		r3.setAmtCoffee("3");
		r3.setAmtMilk("3");
		r3.setAmtSugar("1");
		r3.setPrice("100");
		
		//Set up for r4
		r4 = new Recipe();
		r4.setName("Hot Chocolate");
		r4.setAmtChocolate("4");
		r4.setAmtCoffee("0");
		r4.setAmtMilk("1");
		r4.setAmtSugar("1");
		r4.setPrice("65");
		
		super.setUp();
	}
	
	/////////////////
	//getChocolate()
	/////////////////
	
	public void testGetChocolate() {
		assertEquals(I.getChocolate(), 15);
	}
	
	/////////////////
	//setChocolate(int)
	/////////////////
	
	public void testSetChocolate() {
		I.setChocolate(30);
		assertEquals(I.getChocolate(), 30);
	}
	
	public void testSetChocolateNegative() {
		I.setChocolate(-1);
		assertEquals(I.getChocolate(), 15);
	}
	
	/////////////////
	//addChocolate(String)
	/////////////////
	
	public void testAddChocolate() throws InventoryException {
		try {
			I.addChocolate("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(I.getChocolate(), 25);
	}
	
	public void testAddChocolateBadNumber(){
		try {
			I.addChocolate("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testAddChocolateNegativeNumber() throws NumberFormatException {
		try {
			I.addChocolate("-1");
			fail("InventoryException should be thrown");
		} catch (InventoryException e) {
			//success if thrown
		}
	}
	
	
	/////////////////
	//getSugar()
	/////////////////
	
	public void testGetSugar() {
		assertEquals(I.getSugar(), 15);
	}
	
	/////////////////
	//setSugar(int)
	/////////////////
	
	public void testSetSugar() {
		I.setSugar(30);
		assertEquals(I.getSugar(), 30);
	}
	
	public void testSetSugarNegative() {
		I.setSugar(-1);
		assertEquals(I.getSugar(), 15);
	}
	
	/////////////////
	//addSugar(String)
	/////////////////
	
	public void testAddSugar() throws InventoryException {
		try {
			I.addSugar("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(I.getSugar(), 25);
	}
	
	public void testAddSugarBadNumber(){
		try {
			I.addSugar("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testAddSugarNegativeNumber() throws NumberFormatException {
		try {
			I.addSugar("-1");
			fail("InventoryException should be thrown");
		} catch (InventoryException e) {
			//success if thrown
		}
	}
	
	
	/////////////////
	//getCoffee()
	/////////////////
	
	public void testGetCoffee() {
		assertEquals(I.getCoffee(), 15);
	}
	
	/////////////////
	//setCoffee(int)
	/////////////////
	
	public void testSetCoffee() {
		I.setCoffee(30);
		assertEquals(I.getCoffee(), 30);
	}
	
	public void testSetCoffeeNegative() {
		I.setCoffee(-1);
		assertEquals(I.getCoffee(), 15);
	}
	
	/////////////////
	//addCoffee(String)
	/////////////////
	
	public void testAddCoffee() throws InventoryException {
		try {
			I.addCoffee("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(I.getCoffee(), 25);
	}
	
	public void testAddCoffeeBadNumber(){
		try {
			I.addCoffee("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testAddCoffeeNegativeNumber() throws NumberFormatException {
		try {
			I.addCoffee("-1");
			fail("InventoryException should be thrown");
		} catch (InventoryException e) {
			//success if thrown
		}
	}
	
	
	/////////////////
	//getMilk()
	/////////////////
	
	public void testGetMilk() {
		assertEquals(I.getMilk(), 15);
	}
	
	/////////////////
	//setMilk(int)
	/////////////////
	
	public void testSetMilk() {
		I.setMilk(30);
		assertEquals(I.getMilk(), 30);
	}
	
	public void testSetMilkNegative() {
		I.setMilk(-1);
		assertEquals(I.getMilk(), 15);
	}
	
	/////////////////
	//addMilk(String)
	/////////////////
	
	public void testAddMilk() throws InventoryException {
		try {
			I.addMilk("10");
		} catch (NumberFormatException e) {
			fail("NumberFormatException should not be thrown");
		}
		assertEquals(I.getMilk(), 25);
	}
	
	public void testAddMilkBadNumber(){
		try {
			I.addMilk("AH");
			fail("NumberFormatException should be thrown");
		} catch (Exception e) {
			//success if thrown
		}
	}
	
	public void testAddMilkNegativeNumber() throws NumberFormatException {
		try {
			I.addMilk("-1");
			fail("InventoryException should be thrown");
		} catch (InventoryException e) {
			//success if thrown
		}
	}
	
	////////////////////////////
	//enoughIngredients(Recipe)
	////////////////////////////
	
	public void testEnoughIngredientsTrue() {
		assertTrue(I.enoughIngredients(r1));
	}
	
	public void testEnoughIngredientsFalse() {
		try{
			r1.setAmtCoffee("20");
		} catch (Exception e) {
			fail("RecipeException should not be thrown");
		}
		assertFalse(I.enoughIngredients(r1));
		
		try{
			r2.setAmtChocolate("20");
		} catch (Exception e) {
			fail("RecipeException should not be thrown");
		}
		assertFalse(I.enoughIngredients(r2));
		
		try{
			r3.setAmtMilk("20");
		} catch (Exception e) {
			fail("RecipeException should not be thrown");
		}
		assertFalse(I.enoughIngredients(r3));
		
		try{
			r4.setAmtSugar("20");
		} catch (Exception e) {
			fail("RecipeException should not be thrown");
		}
		assertFalse(I.enoughIngredients(r4));
	}
	
	////////////////////////////
	//useIngredients(Recipe)
	////////////////////////////
	
	public void testUseIngredientsTrue() {
		assertTrue(I.useIngredients(r1));
	}
	
	public void testUseIngredientsFalse() {
		try{
			r1.setAmtCoffee("20");
		} catch (Exception e) {
			fail("RecipeException should not be thrown");
		}
		assertFalse(I.useIngredients(r1));
	}
	
	////////////////////////////
	//toString()
	////////////////////////////
	public void testToString () {
		I.toString();
	}
	
	
	
}
